export let config = {
  key: {},
  feature: {},
  env: {},
  dic: {
    getLabel(dic, value, def='') {
      let one = dic.find(v=>v.value===value)
      return one?one.label:def
    },
    getLabels(dic, value, def='') {
      // dic.filter(v=>value.find(vv=>vv===v.id)).map(v=>v.name).join(',')
      // let one = dic.find(v=>v.value===value)
      // return one?one.label:def
    }
  }
}

export default function($x, {
  configExtend, configKeyExtend, configFeatureExtend, configEnvExtend, configDicExtend
}={}, app) {
  config.systemInfo = uni.getSystemInfoSync() // https://uniapp.dcloud.io/api/system/info?id=getsysteminfo
  config.updateSystemInfo = ()=>config.systemInfo = uni.getSystemInfoSync()
  Object.assign(config.key, configKeyExtend)
  Object.assign(config.feature, configFeatureExtend)
  Object.assign(config.env, {
    version: process.env.VUE_APP_VERSION,
    isIphone: config.systemInfo.model&&config.systemInfo.model.indexOf('iPhone')>=0,
    isIos13: config.systemInfo.system.startsWith('iOS') && (Number(config.systemInfo.system.slice(4,6)) > 13),
    isMobile: (config.systemInfo.platform=='ios' || config.systemInfo.platform=='android') ? true : false,
    // #ifdef APP-PLUS
    hasWechatApp: plus.runtime.isApplicationExist({ pname: 'com.tencent.mm', action: 'weixin://' }),
    // #endif
    // #ifdef APP-PLUS
    isApp: true,
    // #endif
    // #ifdef XT_PC
    isXtPC: true,
    // #endif
    // #ifdef XT_MOBILE
    isXtMobile: true,
    // #endif
  }, configEnvExtend)
  Object.assign(config.dic, configDicExtend)
  Object.assign(config, configExtend)

  $x.config = config
}